package com.bangbang.service.impl;

import com.bangbang.configresult.Result;
import com.bangbang.pojo.TbAdvertising;
import com.bangbang.mapper.TbAdvertisingMapper;
import com.bangbang.pojo.TbAdvertisingColumn;
import com.bangbang.service.ITbAdvertisingColumnService;
import com.bangbang.service.ITbAdvertisingService;
import com.baomidou.mybatisplus.core.conditions.Wrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

/**
 * <p>
 * 广告表 服务实现类
 * </p>
 *
 * @author ${author}
 * @since 2021-08-14
 */
@Service
public class TbAdvertisingServiceImpl extends ServiceImpl<TbAdvertisingMapper, TbAdvertising> implements ITbAdvertisingService {

    @Autowired
    private TbAdvertisingMapper tbAdvertisingMapper;

    @Autowired
    private ITbAdvertisingColumnService columnService;

    @Override
    public List<TbAdvertising> queryAdvertise(Long colId) {
        //查询当前栏位中广告
        QueryWrapper wrapper = new QueryWrapper();
        List<TbAdvertising>  advertisingList = tbAdvertisingMapper.selectList(wrapper);
        if(advertisingList!=null){
            return advertisingList;
        }
        return null;
    }

    @Override
    public TbAdvertising selectById(Long advId) {
        return tbAdvertisingMapper.selectById(advId);
    }

    @Override
    public void insertResultId(TbAdvertising advertising) {
        tbAdvertisingMapper.insertResultId(advertising);
    }

    @Override
    public List<TbAdvertising> queryAdvertiseAtDay() {
        List<TbAdvertisingColumn> list = columnService.list(null);
        if(list==null){
            return null;
        }
        List<TbAdvertising> advertisings = new ArrayList<>();
        for (int i = 0; i < list.size(); i++) {
            Long id = list.get(i).getColId();
            QueryWrapper wrapper = new QueryWrapper();
            wrapper.eq("adv_lanwei_classify",id);
            List<TbAdvertising> list1 = tbAdvertisingMapper.selectList(wrapper);
            for (TbAdvertising t:list1) {
                advertisings.add(t);
            }
        }
        return advertisings;
    }
}
